package com.org.web.handle.classify.service;

import com.org.platform.model.ResultModel;
import com.org.platform.utils.CommonUtil;
import com.org.web.handle.classify.dao.ClassifyMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/** @author devg @Date 2020/2/28 15:16 */
@Service
public class ClassifyService {

  @Autowired
  private ClassifyMapper classifyMapper;

  // @Autowired
  // private RedisTemplate redisTemplate;

  public List<Map<String,Object>> getClassifyList(Map<String, Object> param) {
    //    Integer classifyLevel = CommonUtil.getMapInteger(param,"classifyLevel");
    //    if(classifyLevel.equals(1)){  // 查询一级分类
    //     String classifyKey = "classify:level";
    //     List<Map<String,Object>> classifyList =
    // redisTemplate.opsForList().range(classifyKey,0,-1);
    //     if(CommonUtil.isEmpty(classifyList)){
    //       classifyList = classifyMapper.getClassifyList(param);
    //       redisTemplate.opsForList().rightPushAll(classifyKey,classifyList);
    //       redisTemplate.expire(classifyKey,30, TimeUnit.SECONDS);
    //     }
    //     return classifyList;
    //    }
    Long parentId = CommonUtil.getMapLong(param,"parentId");
    Integer classifyLevel = CommonUtil.getMapInteger(param, "classifyLevel");
    if (null != classifyLevel && classifyLevel.equals(1)) { // 查询一级分类
      return classifyMapper.getOneLevelList(param);
    }else if(null != parentId){
      return classifyMapper.getListByParentId(param);
    }
    return classifyMapper.getClassifyList(param);
  }
}
